<template>
	<div style="height:3000px">
		<!-- 工单领料 -->

			<v-card>
				<v-card-title>
					<v-row >
						<v-col cols="5">
							<v-btn class="ml-2"  tile color="primary" @click.stop="AddDialog()">
								新增
							</v-btn>
							<v-btn class="ml-2"  tile color="error" @click.stop="Cancel()">
								取消
							</v-btn>
							<v-btn class="ml-2"  tile color="accent" @click.stop="AddDetails()">
								新增明细
							</v-btn>
							<v-btn class="ml-2"  tile color="info" @click.stop="GetPutIn()">
								生成入库单
							</v-btn>
							
							
						</v-col>
						<v-col cols="6" >
								<v-row >
									<v-col cols="3" >
										<v-text-field label="单据号" v-model="Ssourceorder" placeholder="单据号" dense outlined>
										</v-text-field>
									</v-col>
										
									<v-col cols="3" >
										<v-text-field label="项目号" v-model="Sproject" placeholder="项目号" dense outlined>
										</v-text-field>
									</v-col>
									
									<v-col cols="2">
										<v-select  v-model="flagselect" :items="flagitems"
															item-text="name"
										          item-value="value"
											outlined dense label="入库完成标识">
										</v-select>
									</v-col>
									
									<v-col cols="2">
										<v-select  v-model="flagpost" :items="postitems"
															item-text="name"
										          item-value="value"
											outlined dense label="过账完成标识">
										</v-select>
									</v-col>
									
									<v-col cols="2">
										<v-btn depressed color="primary" @click="searchinfo()" tile>查询</v-btn>
									</v-col>
								</v-row>																												
						</v-col>
						
						<v-col cols="1" align="end">
							<v-btn dark color="blue lighten-3" @click="refreshApps">
								<v-icon dark>mdi-refresh-circle</v-icon>刷新
							</v-btn>
						</v-col>
						
					</v-row>					
				</v-card-title>
				
				<v-alert dense text color="blue-grey"></v-alert>
				
				<v-data-table :headers="HeaderList" :items="DataList" small dense
					fixed-header item-key="id"  class="text-no-wrap" show-select  v-model="selected"
					loading-text="正在加载请稍等......" :loading="HOrderLoading"
					:options.sync="HOrderOptions" :footer-props="vuetifyDefaultPage"
					:server-items-length="HOrderTotalCount"
					show-expand  single-expand @item-expanded="getdetails">
					<template v-slot:item.type="{ item }">
						<v-chip v-if="item.type == 1" color="primary" small label
							
						>
							采购入库单
						</v-chip>
						<v-chip v-else-if="item.type == 2" color="primary" small label
							
						>
							生产入库单
						</v-chip>
						<v-chip v-else color="primary" small label
							
						>
							其他入库单
						</v-chip>
					</template>
					<template v-slot:item.stockedflag="{ item }">
						<v-chip v-if="item.stockedflag == 0" color="error" small label
							
						>
							未入库
						</v-chip>
						<v-chip v-else color="success" small label
							
						>
							已入库
						</v-chip>
					</template>
					<template v-slot:item.getflag="{ item }">
						<v-chip v-if="item.getflag == 0" color="error" small label
							
						>
							未发送
						</v-chip>
						<v-chip v-else color="success" small label
							
						>
							已发送
						</v-chip>
					</template>
					<template v-slot:item.postflag="{ item }">
						<v-chip v-if="item.postflag == 0" color="error" small label
							
						>
							未过账
						</v-chip>
						<v-chip v-else color="success" small label
							
						>
							已过账
						</v-chip>
					</template>
					<template v-slot:item.state="{ item }">
						<v-chip v-if="item.state == 0" small label
							
						>
							新建
						</v-chip>
						<v-chip v-else-if="item.state == 1" color="accent" small label
							
						>
							正在执行
						</v-chip>
						<v-chip v-else-if="item.state == 2" color="primary" small label
							
						>
							已完成
						</v-chip>
						<v-chip v-else color="error" small label
							
						>
							已取消
						</v-chip>
					</template>
					<template v-slot:item.actions="{ item }">
			      <v-btn tile color="warning" small @click.stop="EditDialog(item)">
							<v-icon left>
								mdi-pencil
							</v-icon>
							编辑
			      </v-btn>
			    </template>
					<template v-slot:expanded-item="{ headers, item }">
						
						<td :colspan="headers.length">
							<v-data-table :headers="DetailsBodyList" :items="DetailsList" small dense
								fixed-header item-key="id"  class="text-no-wrap"
								loading-text="正在加载请稍等......" :loading="DOrderLoading"
								:options.sync="DOrderOptions" :footer-props="vuetifyDefaultPage"
								:server-items-length="DOrderTotalCount">
								<template v-slot:item.state="{ item }">
									<v-chip v-if="item.state == 0"  small label
										
									>
										新建
									</v-chip>
									<v-chip v-else-if="item.state == 1" color="accent" small label
										
									>
										正在执行
									</v-chip>
									<v-chip v-else-if="item.state == 2" color="primary" small label
										
									>
										已完成
									</v-chip>
									<v-chip v-else color="error" small label
										
									>
										已取消
									</v-chip>
								</template>
								<template v-slot:item.feedbackflag="{ item }">
									<v-chip v-if="item.feedbackflag == 0" color="error" small label
										
									>
										未过账
									</v-chip>
									<v-chip v-else color="success" small label
										
									>
										已过账
									</v-chip>
								</template>
								<template v-slot:item.actions="{ item }">
									<v-row>										
										<v-col cols="4">
											<v-btn tile color="warning" small @click.stop="EditDetailsDialog(item)">
												<v-icon left>
													mdi-pencil
												</v-icon>
												编辑
											</v-btn>
										</v-col>
										
										<v-col cols="4">
											<v-btn tile color="error" small @click.stop="DeleteDetails(item)">
												<v-icon left>
													mdi-pencil
												</v-icon>
												删除
											</v-btn>
										</v-col>
										
										<v-col cols="4">
											<v-btn tile color="success" small @click.stop="Feed(item)">
												<v-icon left>
													mdi-pencil
												</v-icon>
												过账
											</v-btn>
										</v-col>
									</v-row>
								</template>
								</v-data-table>								
						</td>
					</template>
				</v-data-table>

			</v-card>
	
	

		<!-- 对话框 -->
		<v-dialog v-model="AddOrEditDialog" max-width="1000px">
			<v-card>
				<v-card-title class="text-h5">
				  {{DialogHeader}}
				</v-card-title>
				<v-card-text>
				  <div class="mb-12">
				  	<v-row dense>
				  		<v-col cols="12">
				  			<v-row>
				  				<v-col cols="12">
				  					<v-text-field label="单据编号"  clearable :rules="[rules.required]"
				  						v-model="DialogBill.sourceorder">
				  					</v-text-field>
				  				</v-col>
				  				<v-col cols="10">
				  					<v-text-field label="项目编码"   clearable :rules="[rules.required]"
				  						v-model="DialogBill.project">
				  					</v-text-field>
				  				</v-col>
				  				<v-col cols="2">
				  					<v-btn class="mt-1" tile color="primary" @click="selectprojectClick">
				  						选择项目</v-btn>
				  				</v-col>
									<!--<v-col cols="6">
										<v-text-field label="入库类别"   clearable :rules="[rules.required]"
											v-model="DialogBill.code">
										</v-text-field>
									</v-col>-->
									<v-col cols="6">
										<v-select clearable required v-model="DialogBill.code"
											:items="RdtypeList" label="入库类型">
										</v-select>
									</v-col>									
									<v-col cols="6">
										<v-select clearable required v-model="DialogBill.warehouse"
										:items="WareList" label="仓库"></v-select>
									</v-col>
									<v-col cols="10">
										<v-text-field label="供应商编码"   clearable :rules="[rules.required]"
											v-model="DialogBill.companycode">
										</v-text-field>
									</v-col>
									<v-col cols="2">
										<v-btn class="mt-1" tile color="primary" @click="selectSupplierClick">
											选择供应商</v-btn>
									</v-col>
				  				<!--<v-col cols="6">
										<v-select  v-model="DialogBill.stockedflag" :items="Sstockedflag"
															item-text="name"
										          item-value="value"
											 label="入库标识">
										</v-select>
				  				</v-col>
									<v-col cols="6">
										<v-select  v-model="DialogBill.getflag" :items="Sgetflag"
															item-text="name"
										          item-value="value"
											 label="接收标识">
										</v-select>
									</v-col>
									<v-col cols="6">
										<v-select  v-model="DialogBill.postflag" :items="Spostflag"
															item-text="name"
										          item-value="value"
											 label="过账标识">
										</v-select>
									</v-col>-->
				  			</v-row>
				  		</v-col>
				  	</v-row>
				  </div>
				</v-card-text>
				<v-card-actions>
				  <v-spacer></v-spacer>
					
				  <v-btn
				    color="green darken-1"
				    text
				    @click="confirmOrder()"
				  >
				    提交
				  </v-btn>
					
				  <v-btn
				    color="green darken-1"
				    text
				    @click="AddOrEditDialog = false"
				  >
				    关闭
				  </v-btn>
				</v-card-actions>
			</v-card>
		</v-dialog>
		
		<!-- 子对话框 -->
		<v-dialog v-model="DetailsDialog" max-width="1000px">
			<v-card>
				<v-card-title class="text-h5">
				  {{DetailsDialogHeader}}
				</v-card-title>
				<v-card-text>
				  <div class="mb-12">
				  	<v-row dense>
				  		<v-col cols="12">
				  			<v-row>
				  				<!--<v-col cols="6">
				  					<v-select  v-model="DetailsBill.state" :items="Tstate"
				  										item-text="name"
				  					          item-value="value"
				  						 label="状态">
				  					</v-select>
				  				</v-col>-->
									<v-col cols="6">
										<v-text-field label="批次"   clearable :rules="[rules.required]"
											v-model="DetailsBill.lot">
										</v-text-field>
									</v-col>
				  				<v-col cols="6">
				  					<v-text-field label="物料编号"   clearable :rules="[rules.required]"
				  						v-model="DetailsBill.itemcode">
				  					</v-text-field>
				  				</v-col>
									<v-col cols="6">
										<v-text-field label="物料名称"   clearable :rules="[rules.required]"
											v-model="DetailsBill.itemname">
										</v-text-field>
									</v-col>
									<v-col cols="6">
										<v-text-field label="规格"   clearable :rules="[rules.required]"
											v-model="DetailsBill.spec">
										</v-text-field>
									</v-col>
									<v-col cols="6">
										<v-text-field label="数量"   clearable :rules="[rules.required,rules.num]"
											v-model="DetailsBill.qty">
										</v-text-field>
									</v-col>
									<v-col cols="6">
										<v-text-field label="单位"   clearable :rules="[rules.required]"
											v-model="DetailsBill.unit">
										</v-text-field>
									</v-col>
									<!--<v-col cols="6">
										<v-select  v-model="DetailsBill.feedbackflag" :items="Tfeedbackflag"
															item-text="name"
										          item-value="value"
											 label="过账标识">
										</v-select>
									</v-col>-->
				  			</v-row>
				  		</v-col>
				  	</v-row>
				  </div>
				</v-card-text>
				<v-card-actions>
				  <v-spacer></v-spacer>
					
				  <v-btn
				    color="green darken-1"
				    text
				    @click="confirmDetailsOrder()"
				  >
				    提交
				  </v-btn>
					
				  <v-btn
				    color="green darken-1"
				    text
				    @click="DetailsDialog = false"
				  >
				    关闭
				  </v-btn>
				</v-card-actions>
			</v-card>
		</v-dialog>
		
		<suppliercomment :supplierCommentModel="supplierCommentModel" :callBack="setSupplierSelectCallBack">
		</suppliercomment>
		
		<projectcomments :projectComment="projectComment" :callBack="setprojectSelectCallBack">
		</projectcomments>
	</div>
</template>

<script>
import suppliercomment from '../../pdm/components/SupplierDataList.vue'
import projectcomments from '../../pdm/components/ProjectDataList.vue'
export default {
  name: 'wms_ordercenter_other_in',
	components: {
		suppliercomment,
		projectcomments
	},
  data: () => ({
		  Ssourceorder:'',
			Sproject:'',
			flagselect:-1,
			flagpost:-1,
			flagitems:[
				{name: '所有', value:-1},
				{name: '未入库', value:0},
				{name: '已入库', value:1},
			],
			postitems:[
				{name: '所有', value:-1},
				{name: '未过账', value:0},
				{name: '已过账', value:1},
			],
			Sstockedflag:[
				{name: '未入库', value:0},
				{name: '已入库', value:1},
			],
			Sgetflag:[
				{name: '未接收', value:0},
				{name: '已接收', value:1},
			],
			Spostflag:[
				{name: '未过账', value:0},
				{name: '已过账', value:1},
			],
			Sstate:[
				{name: '新建', value:0},
				{name: '正在执行', value:1},
				{name: '已完成', value:2},
				{name: '已取消', value:3},
			],
			Tstate:[
				{name: '新建', value:0},
				{name: '正在执行', value:1},
				{name: '已完成', value:2},
				{name: '已取消', value:3},
			],
			Tfeedbackflag:[
				{name: '未过账', value:0},
				{name: '已过账', value:1},
			],
  		AddOrEditDialog: false,
			DetailsDialog:false,
  		HeaderList: [
  			{ text: '入库单号',value: 'sourceorder'},
  			{ text: '单据类型', value: 'type' },
  			{ text: '项目编号', value: 'project' },
  			{ text: '状态', value: 'state' },
				{ text: '入库类别', value: 'code' },
				{ text: '仓库', value: 'warehouse' },
				{ text: '供应商编码', value: 'companycode' },
  			{ text: '入库标识', value: 'stockedflag' },
				{ text: '入库时间', value: 'stockedtime' },
  			{ text: 'ERP发送标识', value: 'getflag' },
  			{ text: 'ERP发送时间', value: 'gettime' },
  			{ text: 'ERP过账标识', value: 'postflag' },			
				{ text: 'ERP过账时间', value: 'posttime' },		
				{ text: '创建人', value: 'created_byname' },
				{ text: '创建时间', value: 'created_time' },
				{ text: '编辑人', value: 'updated_byname' },
				{ text: '编辑时间', value: 'updated_time' },
				{ text: '操作', value: 'actions' },
  		],
			DetailsBodyList:[
				{ text: '物料编号', value: 'itemcode' },
				{ text: '物料名称', value: 'itemname' },
				{ text: '规格', value: 'spec' },
				{ text: '数量', value: 'qty' },
				{ text: '单位', value: 'unit' },
				{ text: '批次', value: 'lot' },
				/*{ text: '供应商编号', value: 'companycode' },
				{ text: '供应商名称', value: 'companyname' },*/
				{ text: '状态', value: 'state' },
				{ text: 'ERP过账标识', value: 'feedbackflag' },
				{ text: 'ERP过账时间', value: 'feedbacktime' },
				{ text: '创建人', value: 'created_byname' },
				{ text: '创建时间', value: 'created_time' },
				{ text: '编辑人', value: 'updated_byname' },
				{ text: '编辑时间', value: 'updated_time' },
				{ text: '操作', value: 'actions' },	
			],
			DialogBill:{
				id:'',
				dbid:'',
				isavailable:true,
				created_by:'',
				created_byname:'',
				updated_by:'',
				updated_byname:'',
				company:'',
				created_time:'',
				updated_time:'',
				accountingbookcode:'',
				
				sourceorder:'',
				type:3,
				project:'',
				state:0,
				stockedflag:0,
				getflag:0,
				postflag:0,
				code:'',
				warehouse:'',
				companycode:''			
			},
			DetailsBill:{
				id:'',
				dbid:'',
				isavailable:true,
				created_by:'',
				created_byname:'',
				updated_by:'',
				updated_byname:'',
				company:'',
				created_time:'',
				updated_time:'',
				accountingbookcode:'',
				
				fatherid:'',		
				itemcode:'',
				itemname:'',
				spec:'',
				qty:'',
				unit:'',
				lot:'',
				companycode:'',
				companyname:'',
				state:0,
				feedbackflag:0,
			},
  		DataList: [],
			DetailsList: [],
			selected:[],
			Detailsselected:[],
  		checkList: [],
			DetailscheckList: [],
			RdtypeList:[],
			WareList:[],
  		vuetifyDefaultPage: {
  			'items-per-page-text': '每页个数',
  			'items-per-page-options': [10, 20, 50, 100]
  		},
  		HOrderLoading: true,
  		HOrderTotalCount: 0,
  		HOrderOptions: {
  			//页数
  			page: 1,
  			//每页行数
  			itemsPerPage: 10
  		},
  		DOrderLoading: true,
  		DOrderTotalCount: 0,
  		DOrderOptions: {
  			//页数
  			page: 1,
  			//每页行数
  			itemsPerPage: 10
  		},
			DialogHeader:"",
			DetailsDialogHeader:"",
			rules: {
          required: value => !!value || '值不能为空！',
          counter: value => value.length <= 20 || '字符长度不能超过20!',
					num: value => value > 0 || '值要大于0！',
					true: value => {
						const pattern = /^[0-9]*$/
						return pattern.test(value) || '请输入合法数字!'
					}
       },
			 SelectID:"",
			 projectComment: {
			 	dialog: false,
			 	loadprojectUrl: `PDM/PDMInfoManage/LoadPage`
			 },
			 supplierCommentModel: {
			 	dialog: false,
			 	loadSupplierUrl: `PDM/PDMPurchaseNeed/LoadSupplierPage`
			 },
			 
  	}),
		//初始化
  	created() {  
			//获取单据信息
  		this.loadDataList();
			this.SyncGetRdtype();
			this.GetWareCode();
  	},
		//监控分页变化
		watch: {
			HOrderOptions: {
				handler() {
					this.loadDataList()
				},
				deep: true
			},
			DOrderOptions: {
				handler() {
					this.loaddetails()
				},
				deep: true
			},
		},
  	methods: {
  		//搜索
  		search() {
  			this.loadCuttingDetailList()
  		},
  		//加载单据信息
  		loadDataList() {
  			var that = this;
				that.HOrderLoading = true;
				that.DataList = [];
  			this.$httpRequest({
  				url: `WMS/WmsBillOtherIn/GetBillListByPage?Stype=3&pageIndex=${this.HOrderOptions.page}&pageSize=${this.HOrderOptions.itemsPerPage}`,
  				method: 'get'
  			}).then(function(response) {
  				if (response.status == 1) {
  					that.DataList = response.data.result;
						that.HOrderTotalCount = response.data.pagination.totalRecords;
						that.HOrderLoading = false;
  				} else {
  					that.$message.error(response.info);	
  				}
  			})
  		},
			//加载明细
			getdetails(item){
				this.SelectID = item.item.id;
				var that = this;
				that.DetailsList = [];
				that.DOrderLoading = true;
				this.$httpRequest({
					url: `WMS/WmsBillOtherInDetails/GetBillListByPage?id=${item.item.id}&pageIndex=${this.DOrderOptions.page}&pageSize=${this.DOrderOptions.itemsPerPage}`,
					method: 'get'
				}).then(function(response) {
					if (response.status == 1) {
						that.DetailsList = response.data.result;
						that.DOrderTotalCount = response.data.pagination.totalRecords;
						that.DOrderLoading = false;
					} else {
						that.$message.error(response.info);	
					}
				})
			},
			//刷新明细
			loaddetails(){
				var that = this;
				that.DetailsList = [];
				that.DOrderLoading = true;
				this.$httpRequest({
					url: `WMS/WmsBillOtherInDetails/GetBillListByPage?id=${this.SelectID}&pageIndex=${this.DOrderOptions.page}&pageSize=${this.DOrderOptions.itemsPerPage}`,
					method: 'get'
				}).then(function(response) {
					if (response.status == 1) {
						that.DetailsList = response.data.result;
						that.DOrderTotalCount = response.data.pagination.totalRecords;
						that.DOrderLoading = false;
					} else {
						that.$message.error(response.info);	
					}
				})
			},
  		// 打开编辑对话框
  		EditDialog(item) {
				if(item.state != 0)
				{
					this.$message.error("主表已经提交了，不可修改！");
				}
				else
				{
					this.DialogBill.id = item.id;
					this.DialogBill.dbid = item.dbid;
					this.DialogBill.isavailable = item.isavailable;
					this.DialogBill.created_by = item.created_by;
					this.DialogBill.created_byname = item.created_byname;
					this.DialogBill.updated_by = item.updated_by;
					this.DialogBill.updated_byname = item.updated_byname;				
					this.DialogBill.company = item.company;
					this.DialogBill.created_time = item.created_time;
					this.DialogBill.updated_time = item.updated_time;
					this.DialogBill.accountingbookcode = item.accountingbookcode;
					this.DialogBill.sourceorder = item.sourceorder;
					this.DialogBill.type = item.type;
					this.DialogBill.project = item.project;
					this.DialogBill.state = item.state;
					this.DialogBill.stockedflag = item.stockedflag;
					this.DialogBill.stockedtime = item.stockedtime;
					this.DialogBill.getflag = item.getflag;
					this.DialogBill.gettime = item.gettime;
					this.DialogBill.postflag = item.postflag;
					this.DialogBill.posttime = item.posttime;
					this.DialogBill.code = item.code;
					this.DialogBill.warehouse = item.warehouse;
					this.DialogBill.companycode = item.companycode;
					this.DialogHeader = "编辑采购单";
					this.AddOrEditDialog = true;
				}				
  		},
			// 打开新增对话框
			AddDialog() {
				this.DialogBill.sourceorder = "";
				this.DialogBill.type = 3;
				this.DialogBill.project = "";
				this.DialogBill.state = 0;
				this.DialogBill.stockedflag = 0;
				this.DialogBill.getflag = 0;
				this.DialogBill.postflag = 0;
				this.DialogBill.code = '';
				this.DialogBill.warehouse = "",
				this.DialogBill.companycode = "",
				this.DialogHeader = "新增采购单";
				this.AddOrEditDialog = true;
			},
			// 打开编辑明细对话框
			EditDetailsDialog(item) {
				this.DetailsBill.id = item.id;
				this.DetailsBill.dbid = item.dbid;
				this.DetailsBill.isavailable = item.isavailable;
				this.DetailsBill.created_by = item.created_by;
				this.DetailsBill.created_byname = item.created_byname;
				this.DetailsBill.updated_by = item.updated_by;
				this.DetailsBill.updated_byname = item.updated_byname;
				this.DetailsBill.company = item.company;
				this.DetailsBill.created_time = item.created_time;
				this.DetailsBill.updated_time = item.updated_time;
				this.DetailsBill.accountingbookcode = item.accountingbookcode;
				this.DetailsBill.fatherid = item.fatherid;
				this.DetailsBill.state = item.state;
				this.DetailsBill.itemcode = item.itemcode;
				this.DetailsBill.itemname = item.itemname;
				this.DetailsBill.spec = item.spec;
				this.DetailsBill.qty = item.qty;
				this.DetailsBill.unit = item.unit;
				this.DetailsBill.lot = item.lot;
				this.DetailsBill.companycode = item.companycode;
				this.DetailsBill.companyname = item.companyname;	
				this.DetailsBill.feedbackflag = item.feedbackflag;		
				this.DetailsDialogHeader = "编辑明细";
				this.DetailsDialog = true;
			},
			// 打开新增明细对话框
			AddDetailsDialog() {
				this.DetailsBill.fatherid = this.SelectID;
				this.DetailsBill.state = 0;
				this.DetailsBill.itemcode = "";
				this.DetailsBill.itemname = "";
				this.DetailsBill.spec = "";
				this.DetailsBill.qty = "";
				this.DetailsBill.unit = "";
				this.DetailsBill.lot = "";
				this.DetailsBill.companycode = "";
				this.DetailsBill.companyname = "";
				this.DetailsBill.feedbackflag = 0;
				this.DetailsDialogHeader = "新增明细";
				this.DetailsDialog = true;
			},
  		//主表提交
  		confirmOrder() {
  			var that = this;
				if(that.DialogHeader == "新增采购单")
				{
					this.$httpRequest({
						url: `/WMS/WmsBillOtherIn/Add`,
						method: 'post',
						data:{					
								sourceorder : that.DialogBill.sourceorder,
								type : that.DialogBill.type,
								project : that.DialogBill.project,
								state : that.DialogBill.state,
								stockedflag : that.DialogBill.stockedflag,
								getflag : that.DialogBill.getflag,
								postflag : that.DialogBill.postflag,	
								code : that.DialogBill.code,	
								warehouse : that.DialogBill.warehouse,	
								companycode : that.DialogBill.companycode,	
						}
					}).then(function(response) {
					
						if (response.status == 1) {
							that.loadDataList();
							that.AddOrEditDialog = false;
							that.$message.success("新增采购单成功！");
						} else {
							that.$message.error(response.info);	
						}
					})
				}
				else
				{
					this.$httpRequest({
						url: `/WMS/WmsBillOtherIn/Update`,
						method: 'post',
						data:{		
								id : that.DialogBill.id,
								dbid : that.DialogBill.dbid,
								isavailable : that.DialogBill.isavailable,
								created_by : that.DialogBill.created_by,
								created_byname : that.DialogBill.created_byname,
								updated_by : that.DialogBill.updated_by,
								updated_byname : that.DialogBill.updated_byname,
								company : that.DialogBill.company,
								created_time : that.DialogBill.created_time,
								updated_time : that.DialogBill.updated_time,								
								accountingbookcode : that.DialogBill.accountingbookcode,
								sourceorder : that.DialogBill.sourceorder,
								type : that.DialogBill.type,
								project : that.DialogBill.project,
								state : that.DialogBill.state,
								stockedflag : that.DialogBill.stockedflag,
								getflag : that.DialogBill.getflag,
								postflag : that.DialogBill.postflag,	
								code : that.DialogBill.code,
								warehouse : that.DialogBill.warehouse,	
								companycode : that.DialogBill.companycode,
						}
					}).then(function(response) {
					
						if (response.status == 1) {
							that.loadDataList();
							that.AddOrEditDialog = false;
							that.$message.success("更新采购单成功！");
						} else {
							that.$message.error(response.info);	
						}
					})
				}
  			
  		},
			//提交子表
			confirmDetailsOrder() {
				var that = this;
				if(that.DetailsDialogHeader == "新增明细")
				{
					this.$httpRequest({
						url: `/WMS/WmsBillOtherInDetails/Add`,
						method: 'post',
						data:{					
								fatherid : that.SelectID,
								state : that.DetailsBill.state,
								itemcode : that.DetailsBill.itemcode,
								itemname : that.DetailsBill.itemname,
								spec : that.DetailsBill.spec,
								qty : that.DetailsBill.qty,
								unit : that.DetailsBill.unit,
								lot : that.DetailsBill.lot,
								companycode : that.DetailsBill.companycode,
								companyname : that.DetailsBill.companyname,
								feedbackflag: that.DetailsBill.feedbackflag,
						}
					}).then(function(response) {
					
						if (response.status == 1) {
							that.loaddetails();
							that.DetailsDialog = false;
							that.$message.success("新增明细成功！");
						} else {
							that.$message.error(response.info);	
						}
					})
				}
				else
				{
					this.$httpRequest({
						url: `/WMS/WmsBillOtherInDetails/Update`,
						method: 'post',
						data:{		
								id : that.DetailsBill.id,
								dbid : that.DetailsBill.dbid,
								isavailable : that.DetailsBill.isavailable,
								created_by : that.DetailsBill.created_by,
								created_byname : that.DetailsBill.created_byname,
								updated_by : that.DetailsBill.updated_by,
								updated_byname : that.DetailsBill.updated_byname,
								company : that.DetailsBill.company,
								created_time : that.DetailsBill.created_time,
								updated_time : that.DetailsBill.updated_time,
								accountingbookcode : that.DetailsBill.accountingbookcode,
								fatherid : that.DetailsBill.fatherid,
								state : that.DetailsBill.state,
								itemcode : that.DetailsBill.itemcode,
								itemname : that.DetailsBill.itemname,
								spec:that.DetailsBill.spec,
								qty : that.DetailsBill.qty,
								unit : that.DetailsBill.unit,
								lot : that.DetailsBill.lot,
								companycode : that.DetailsBill.companycode,
								companyname : that.DetailsBill.companyname,
								feedbackflag: that.DetailsBill.feedbackflag,
						}
					}).then(function(response) {
					
						if (response.status == 1) {
							that.loaddetails();
							that.DetailsDialog = false;
							that.$message.success("更新明细成功！");
						} else {
							that.$message.error(response.info);	
						}
					})
				}				
			},	
  		//关闭主表新建编辑对话框
  		cancelOrder() {
  			this.AddOrEditDialog = false;
  		},
			//删除主表
			deleteOrder(){
				var that = this;
				for(var i=0; i<that.selected.length; i++)
				{
					this.$httpRequest({
						url: `/WMS/WmsBillOtherIn/Delete/${that.selected[i].id}`,
						method: 'delete'											
					}).then(function(response) {					
						if (response.status == 1) {							
							that.$message.success("删除成功！");							
						} else {
							that.$message.error(response.info);
						}
					})
				}
				that.loadDataList();
			},
			//取消主表
			Cancel(){
				var that = this;
				for(var i=0; i<that.selected.length; i++)
				{
					this.$httpRequest({
						url: `/WMS/WmsBillOtherIn/Cancel/${that.selected[i].id}`,
						method: 'post'											
					}).then(function(response) {					
						if (response.status == 1) {							
							that.$message.success("取消成功！");							
						} else {
							that.$message.error(response.info);
						}
					})
				}
				that.loadDataList();
			},
			//删除明细
			DeleteDetails(item)
			{
				var that = this;
				this.$httpRequest({
					url: `/WMS/WmsBillOtherInDetails/Delete/${item.id}`,
					method: 'delete'	
				}).then(function(response){
					if(response.status == 1)
					{
						that.$message.success("删除明细成功！");		
					} else {
						that.$message.error(response.info);
					}
				})
				that.loaddetails();
			},
			//过账
			Feed(item)
			{
				var that = this;
				this.$httpRequest({
					url: `/WMS/WmsBillOtherInDetails/Feed?id=${item.id}`,
					method: 'get'	
				}).then(function(response){
					if(response.status == 1)
					{
						that.$message.success("过账成功！");		
					} else {
						that.$message.error(response.info);
					}
				})
				that.loaddetails();
			},
			//条件查询主表
			searchinfo(){
				var that = this
				that.HOrderLoading = true;
				this.$httpRequest({
					url: `WMS/WmsBillOtherIn/Search?Stype=3&Sproject=${this.Sproject}&Ssourceorder=${this.Ssourceorder}&Sflag=${this.flagselect}&Spost=${this.flagpost}&pageIndex=${this.HOrderOptions.page}&pageSize=${this.HOrderOptions.itemsPerPage}`,
					method: 'get'
				}).then(function(response) {
					if (response.status == 1) {
						that.DataList = response.data.result;
						that.HOrderTotalCount = response.data.pagination.totalRecords;
						that.HOrderLoading = false;
					} else {
						that.$message.error(response.info);	
					}
				})
			},
			//刷新
			refreshApps(){
				this.Ssourceorder = "";
				this.Sproject = "";
				this.flagselect = -1;
				this.selected = [];
				this.HOrderOptions.page = 1;
				this.loadDataList();
				this.loaddetails();
			},
			//添加明细
			AddDetails(){
				if(this.selected.length == 0)
				{
					this.$message.error("请选择一条主表数据！");	
				}
				else if(this.selected.length > 1)
				{
					this.$message.error("请不要多选！");	
				}
				else if(this.selected[0].state != 0)
				{
					this.$message.error("主表已经提交，不可再添加明细");	
				}
				else
				{
					this.SelectID = this.selected[0].id;
					this.AddDetailsDialog();
					this.DetailsDialog = true;
				}
			},
			//创建入库单
			GetPutIn(){
				if(this.selected.length == 0)
				{
					this.$message.error("请选择一条主表数据！");	
				}
				else if(this.selected.length > 1)
				{
					this.$message.error("请不要多选！");	
				}
				else
				{
					this.SelectID = this.selected[0].id;
					var that = this
					this.$httpRequest({
						url: `WMS/WmsBillOtherIn/Commit?id=${this.SelectID}&state=${this.selected[0].state}`,
						method: 'get'
					}).then(function(response) {
						if (response.status == 1) {
							that.$message.success("生成入库单成功！");
							that.loadDataList();
						} else {
							that.$message.error(response.info);
						}
					})
				}
			},
			//获取入库类型
			SyncGetRdtype(){
				var that = this;
				this.$httpRequest({
					url:`WMS/WmsBillOtherIn/SyncGetRdtype`,
					method:'get'
				}).then(function(response){
					if(response.status == 1)
					{
						that.RdtypeList = response.data;
						console.log(response);
					}						
					else{
						console.log(response);
					}
				})
			},
			//获取仓库类型
			GetWareCode(){
				var that = this;
				this.$httpRequest({
					url:`WMS/WmsBillOtherIn/GetWareCode`,
					method:'get'
				}).then(function(response){
					if(response.status == 1)
					{
						that.WareList = response.data;
					}
					else
					{
						
					}
				})
			},
			selectSupplierClick() {
				this.supplierCommentModel.dialog = true
			},
			setSupplierSelectCallBack(supplier) {
				this.DialogBill.companycode = supplier.cVenCode
			},
			selectprojectClick() {
				this.projectComment.dialog = true
			},
			setprojectSelectCallBack(supplier) {
				this.DialogBill.project = supplier.citemcode
			},
  	}
  
  }

</script>

<style>
	$select-small-chips-dense-selections-min-height{
		height:40px;
	}
</style>
